import {
  http
} from '../../../utils/http/axios';
import {
  ref
} from '@vue/composition-api';

export const useAreaList = () => {
  const areaList = ref();

  const getAreaList = () => {
    http({
      url: '/Api/MF_ManagerFront/MF_ChannelDealer/PostAreaList',
      method: 'post'
    }).then((res) => {
      areaList.value = {
        province_list: Object.assign({}, ...res.PList.map(item => ({
          [item.Id]: item.Name
        }))),
        city_list: Object.assign({}, ...res.CList.map(item => ({
          [item.Id]: item.Name
        }))),
        county_list: Object.assign({}, ...res.DList.map(item => ({
          [item.Id]: item.Name
        })))
      };
    });
  };

  return {
    areaList,
    getAreaList
  };
};